import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class CovidGroupingBean implements WritableComparable<CovidGroupingBean> {
    private int cardid; //员工id
    private String name; //员工名字
    private int wages; // 工资
    private int commision; // 提成
    private int partid; // 部门id

    public int getCardid() {
        return cardid;
    }

    public void setCardid(int cardid) {
        this.cardid = cardid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getwages() {
        return wages;
    }

    public void setwages(int wages) {
        this.wages = wages;
    }

    public int getCommision() {
        return commision;
    }

    public void setCommision(int commision) {
        this.commision = commision;
    }

    public int getPartid() {
        return partid;
    }

    public void setPartid(int partid) {
        this.partid = partid;
    }


    @Override
    public String toString() {
        return "CovidGroupingBean{" +
                "cardid='" + cardid + '\'' +
                ", name=" + name + '\'' +
                ", wages=" + wages + '\'' +
                ", wages=" + commision + '\'' +
                ", partid=" + partid +
                '}';
    }

    //指定排序规则，将分类后的每个员工的薪资(基本工资 + 提成)进行降序排序
    @Override
    public int compareTo(CovidGroupingBean o) {
        int Sunwages = this.getwages() + this.getCommision();
        int OldWages = o.getwages() + o.getCommision();
        //判断是否一个同一个部门
        int reslut = Integer.toString(this.getPartid()).compareTo(Integer.toString(o.getPartid()));
        if (reslut == 0) {
            return (Sunwages - OldWages) * -1;
        }
        return reslut;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(cardid);
        out.writeUTF(name);
        out.writeInt(wages);
        out.writeInt(commision);
        out.writeInt(partid);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.cardid = in.readInt();
        this.name = in.readUTF();
        this.wages = in.readInt();
        this.commision = in.readInt();
        this.partid = in.readInt();
    }


}
